
// 引入axios
const axios = require('axios')
// // 导出模块对象
module.exports = {
	// 获取预约审核列表
    list: async (ctx, next) => {
        const {status} = ctx.request.body
        const {startPage,endPage} = await ctx.service.utils.paging(ctx)
        await ctx.db.query('select * from yuyueorder where status=?',[status]).then(async res=>{
            const total =  res[0].length
            await ctx.db.query('select * from yuyueorder where status=? order by createTime desc limit ?,?',[status,startPage,endPage]).then(async ress=>{
                ctx.body = {
                    code:200,
                    msg:'获取成功',
                    orderList:ress[0],
                    total:total,
                }
            }).catch(err=>{
                ctx.body = {
                    code:300,
                    msg:'获取失败'+err,
                }
            })
        })
    },
   
    // 添加动态
    add: async (ctx, next) => {
        const {userId,userName,userAvatar,momentImg,momentContent} = ctx.request.body
            try {
                let [updateRes] = await ctx.db.query('insert into moment(userId,userName,userAvatar,momentImg,momentContent,createTime) values(?,?,?,?,?,?)', 
                    [userId,userName,userAvatar,JSON.stringify(momentImg),momentContent,new Date()])
                if(updateRes.affectedRows >=1){
                    return ctx.body = {
                        code:200,
                        msg:'添加成功'
                    }
                }else{
                    return ctx.body = {
                        code:300,
                        msg:'添加失败'
                    }
                }
            } catch (error) {
                return ctx.body = {
                    code:500,
                    msg:'添加失败'+error
                }
            }
    },
}